package stack_queue;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description: 每日温度
 * User: Li_yizYa
 * Date: 2025/9/3
 * Time: 15:02
 */
public class Solution8 {
    public static void main(String[] args) {
        int[] temperatures = {73, 74, 75, 71, 69, 72, 76, 73};
        Stack<Integer> stack = new Stack<>();
        int[] ret = new int[temperatures.length];
        for (int i = 0; i < temperatures.length; i++) {
            int temperature = temperatures[i];
            while (!stack.isEmpty() && temperature > temperatures[stack.peek()]) {
                int preIndex = stack.pop();
                ret[preIndex] = i - preIndex;
            }
            stack.push(i);
        }
        for (int i : ret) {
            System.out.print(i + " ");
        }
    }
}
